package com.duan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
 * 
* Title: ConsumerController
* Description:   
* @author duanws
* @date 2018年7月5日
 */
@RestController
public class ConsumerController {

	@Autowired
	LoadBalancerClient loadBalancerClient;
	
	@Autowired
	RestTemplate restTemplate;
	
	@GetMapping("/consumer")
	public String consumer(){
		ServiceInstance serviceInstance = loadBalancerClient.choose("Eureka-client");
		String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/hello";
		System.out.print(url);
		String rep = this.restTemplate.getForObject(url, String.class);
		return rep;
	}
}
